// ===============================================
// token
//
// Create by Will on 8/3/2024 23:54
// Copyright @polynesia.All rights reserved.
// ===============================================

import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

/// This allows the `Token` class to access private members in
/// the generated file. The value for this is *.g.dart, where
/// the star denotes the source file name.
part 'token.g.dart';

/// An annotation for the code generator to know that this class needs the
/// JSON serialization logic to be generated.
@JsonSerializable(genericArgumentFactories: true)
class Token {
  const Token({
    this.tokenType,
    this.accessToken,
    this.accessTokenExpire,
    this.refreshToken,
    this.refreshTokenExpire,
  });

  /// A necessary factory constructor for creating a new Token instance
  /// from a map. Pass the map to the generated `_$TokenFromJson()` constructor.
  /// The constructor is named after the source class, in this case, Token.
  factory Token.fromJson(Map<String, dynamic> json) => _$TokenFromJson(json);

  @JsonKey(name: 'token_type')
  final String? tokenType;
  @JsonKey(name: 'access_token')
  final String? accessToken;
  @JsonKey(name: 'access_token_expire')
  final int? accessTokenExpire;
  @JsonKey(name: 'refresh_token')
  final String? refreshToken;
  @JsonKey(name: 'refresh_token_expire')
  final int? refreshTokenExpire;

  /// `toJson` is the convention for a class to declare support for serialization
  /// to JSON. The implementation simply calls the private, generated
  /// helper method `_$TokenToJson`.
  Map<String, dynamic> toJson() => _$TokenToJson(this);

  bool isEmpty() {
    const Token entity = Token();
    // if (entity.toString() == toString()) {
    //   return true;
    // }
    return jsonEncode(entity) == jsonEncode(this);
  }
}
